package com.dempsey.controller;

import com.dempsey.dao.User;
import com.dempsey.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Dempsey
 * Date 2022/2/8
 * Description
 */

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/queryUserList")
    public List<User> queryUserList() {
        return userMapper.queryUserList();
    }

    @GetMapping("/queryUserById/{id}")
    List<User> queryUserById(@PathVariable("id") Integer id) {
        return userMapper.queryUserById(id);
    }

    @PostMapping("/addUser")
    String addUser(@RequestBody User user) {
        userMapper.addUser(user);
        return"add Ok";
    }

    @PutMapping("/updateUser/{id}")
    String updateUser(@RequestBody User user) {
        userMapper.updateUser(user);
        return "update Ok";
    }

    @DeleteMapping("/deleteById/{id}")
    String deleteById(@PathVariable("id") Integer id) {
        userMapper.deleteById(id);

        return "delete Ok";
    }
}
